<template>
    <div class="pageContainer">
        <div class="searchWarp">
            <el-form inline>
                <template v-for="condition in listCondition">
                    <CText :title="condition.name" v-model="condition.value"></CText>
                </template>
            </el-form>
            <div class="schLine">
                <CBtn @click="search(1)">查询</CBtn>
            </div>
        </div>
        <div class="treeTable">
            <CCateTree :treeData="treeData" @nodeClick="nodeClick"></CCateTree>
            <div style="flex:1;">
                <div class="btnWarp">
                    <CBtn @click="showMyEdit">新增</CBtn>
                    <CBtn @click="doBatchDel()">批量删除</CBtn>
                </div>
                <CPageTable :data="tableData" :curPage="paging.curPage" :total="paging.total" 
                    @changeSelect="changeSelect"
                    @changeSize="changeSize" @changePage="search">
                    <template slot-scope="scope">
                        <CBtn type="text" @click="showCopy(scope.row)">复制</CBtn>
                        <CBtn type="text" @click="showMyEdit(scope.row)">修改</CBtn>
                        <CBtn type="text" @click="doDel(scope.row)">删除</CBtn>
                    </template>

                </CPageTable>
            </div>
        </div>

        <CDailog title="新增/编辑" :isShow="isShowEdit" @close="isShowEdit = false" @enter="doSave">
            <el-form :inline="true">
                <CSelect form v-model="mm.tableName" title="表名" field="tableName" opType="opTables"></CSelect>
                <CText form v-model="mm.columnName" title="字段名" field="columnName"></CText>
                <CSelect form v-model="mm.checkMethod" title="检查函数" field="checkMethod" opType="opCheckMethod" multiple></CSelect>
                <CText form v-model="mm.msg" title="信息替换" field="msg"></CText>
                <CText form v-model="mm.minLength" title="最小长度" field="minLength"></CText>
                <CText form v-model="mm.maxLength" title="最大长度" field="maxLength"></CText>
                <CText form v-model="mm.repeatTableName" title="重复性校验表名" field="repeatTableName"></CText>
                <CText form v-model="mm.repeatColumnName" title="重复性校验字段名" field="repeatColumnName"></CText>
            </el-form>
        </CDailog>
    </div>
</template>

<script>
import pagingMixin from '@/mixin/pagingMixin'
export default {
    mixins: [pagingMixin],
    data() {
        return {
            treeData: [],
            model: "sys",
            table: "SysValidator",
            curTreeNode: {}
        }
    },
    created() {
        this.templateId = "1f94ac00-110e-4f52-98fc-9d09ab3e6490";
        //查询树形
        this.searchTree();
        
        //取得查询条件
        this.$sys.getPageConditions({id: this.templateId}).then(res => {
            this.listCondition = res.data;
        })
        //查询表格数据
        this.search(1);
    },
    methods: {
        searchTree() {
            this.$sys.getTreeByCode({code: "opTables"}).then(res => {
                this.treeData = res.data;
                
            })
        },
        nodeClick(node) {
            this.otherCondition = [];
            this.$u.addWhere(this.otherCondition, "table_name", node.id);
            this.search(1, [...this.listCondition, ...this.otherCondition]);
            this.curTreeNode = node;
        },
        showMyEdit(row) {
            this.showEdit(row);
            this.$set(this.mm, "tableName", this.curTreeNode.id);
        },
        showCopy(row) {
            this.$sys.getById(this.model, this.table, {id: row.id}).then(res => {
                this.mm = res.data;
                this.mm.id = "";
                this.isShowEdit = true;
            })
        }
    }
}
</script>

<style lang="scss" scoped></style>